package com.cuz.daileetcode;

/****
 * 见
 * 【DaiLeetCode41小虎买苹果——贪心，打表法】
 *
 */
public class Day41 {


    static class Greedy {

        static int solution(int appleWeNeed) {
            //小于0 or 为奇数直接返回-1
            if (appleWeNeed < 0 || (appleWeNeed & 1) != 0) {
                return -1;
            }
            int suit8 = appleWeNeed / 8;
            int suit6 = -1;
            int rest = appleWeNeed - 8 * suit8;
            while (suit8 >= 0 && rest < 24) {
                if (rest % 6 == 0) {
                    suit6 = rest / 6;
                    break;
                }
                suit8--;
                rest = appleWeNeed - 8 * suit8;
            }
            if (suit6 != -1) {
                return suit6 + suit8;
            }
            return -1;
        }
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            if (i % 2 == 0 && i >= 6) {
                System.out.println(i + "====>" + Greedy.solution(i));
            }
        }
    }

    static int solution(int appleWeNeed) {
        //小于0 or 为奇数直接返回-1
        if (appleWeNeed < 0 || (appleWeNeed & 1) != 0) {
            return -1;
        }
        if (appleWeNeed < 18) {
            switch (appleWeNeed) {
                case 0:
                    return 0;
                case 6:
                case 8:
                    return 1;
                case 12:
                case 14:
                case 16:
                    return 2;
                default:
                    return -1;
            }
        }
        return (appleWeNeed - 18) / 8 + 3;
    }
}
